package com.yf.zzmusic.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yf.zzmusic.common.Result;
import com.yf.zzmusic.pojo.dto.musicCollectRecord.MusicCollectRecordDeleteDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

import com.yf.zzmusic.service.IMusicCollectRecordService;
import com.yf.zzmusic.pojo.entity.MusicCollectRecord;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 歌单记录表，为减少music_collec表的数据的冗余 前端控制器
 * </p>
 *
 * @author
 * @since 2024-02-26
 */
@RestController
@RequestMapping("/musicCollectRecord")
public class MusicCollectRecordController {
    @Resource
    private IMusicCollectRecordService musicCollectRecordService;

    @PostMapping("/insert")
    public Result save(@Validated @RequestBody  MusicCollectRecord musicCollectRecord) {
        boolean result=musicCollectRecordService.save(musicCollectRecord);
        if (result){
            return Result.success("新增成功");
        }else{
            return Result.error("新增失败");
        }
    }

    //删除歌单中的一首歌曲
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        boolean result=musicCollectRecordService.removeById(id);
        if (result){
            return Result.success("删除成功");
        }else{
            return Result.error("删除失败");
        }
    }

    //根据音乐删除,当音乐删除被删除时,应执行该操作
    @DeleteMapping("/musicId/{id}")
    public Result deleteByMusicId(@PathVariable Integer id) {
        boolean result=musicCollectRecordService.deleteMusicCollectRecordByMusicId(id);
        if (result){
            return Result.success("删除成功");
        }else{
            return Result.error("删除失败");
        }
    }

    //根据歌单id删除
    @DeleteMapping("/musicCollectId/{id}")
    public Result deleteByMusicCollectId(@PathVariable Integer id) {
        boolean result=musicCollectRecordService.deleteMusicCollectRecordByMusicCollectId(id);
        if (result){
            return Result.success("删除成功");
        }else{
            return Result.error("删除失败");
        }
    }

    //无修改操作

    @GetMapping("/{id}")
    public List<MusicCollectRecord> findOne(@PathVariable Integer id) {
        return musicCollectRecordService.list();
    }

    @GetMapping("/page")
    public Page<MusicCollectRecord> findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
        return null;
    }
}

